package com.li.utils;

import cn.hutool.core.io.FileUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FileMoveUtil {
    /**
     * @Description: String src  原路径名称
     * String dest  新路径名称
     */
    public static Integer moveFile(String src, String dest) {
        int count =0;
        List<File> fileList = new ArrayList<>();
        File file = FileUtil.file(src);
        getFileList(file, fileList);
        List<File> filePath = new ArrayList<>();
        for (File s : fileList) {
            String fileName = s.getName();
            if (fileName.contains(".mp4")) {
                filePath.add(s);
            }
        }
        for (File orgFile : filePath) {
            count++;
            File destFile = new File(dest);
            FileUtil.move(orgFile, destFile, false);
        }
        return count;
    }


    private static void getFileList(File file, List<File> list) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            assert files != null;
            for (File file1 : files) {
                getFileList(file1, list);
            }
        } else {
            list.add(file);
        }
    }
}
